<!DOCTYPE html>
<html>

<head>
    <meta charset="utf-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <link rel="stylesheet" type="text/css" href="__PUBLIC__css/public.css">
    <script type="text/javascript" src="__PUBLIC__/js/jquery.min.js"></script>
    <script type="text/javascript" src="__PUBLIC__/js/jquery.SuperSlide.js"></script>
    <title>新增同步接口</title>
    <link rel="stylesheet" href="">
    <style type="text/css">
    select {
        height: 24px;
        width: 100px;
    }
    
    form {
        width: 60%;
        height: 60%;
        margin: 0 auto;
        border: 1px solid red;
        margin-top: 20px;
        padding: 5px;
    }
    </style>
    <script type="text/javascript">
    function selectType(obj) {
        document.getElementById("servcode").options.remove(0);
        document.getElementById("servcode").options.remove(0);
        document.getElementById("servcode").options.remove(0);


        var v = $(obj).val();
        if (v == 0) {
            $("#servcode").append("<option value='WTD'>WD</option>");
            $("#servcode").append("<option value='WTS'>WS</option>");
            $("#servcode").append("<option value='WTV'>WV</option>");
        } else {
            $("#servcode").append("<option value='WX1234'>WX1234</option>");
            $("#servcode").append("<option value='WX5678'>WX5678</option>");
            $("#servcode").append("<option value='WX2'>WX2</option>");
            $("#servcode").append("<option value='WX3'>WX3</option>");
            $("#servcode").append("<option value='WX4'>WX4</option>");

        }
        // alert(v);
    }
    /**
     * 验证url不为空
     * @param  {[type]} obj [description]
     * @return {[type]}     [description]
     */
    function validate(obj) {
        var url = $("input[name='url']").val();
        if (url == '' || url == undefined) {
            $('#tips').html("第三方同步接口地址不能为空！");
            $("input[name='url']").focus();
            return false;
        } else {
            return true;
        }
    }



    function addSyncInterface() {
        var type = $("select[name=type]").val();
        var servcode = $("select[name=servcode]").val();
        var url = $("input[name=url]").val();

        if (url == '' || url == undefined) {
            $('#tips').html("第三方同步接口地址不能为空！");
            $("input[name='url']").focus();
            return false;
        }
        $.ajax({
            cache: true,
            type: "POST",
            url: "{:U('config/addSyncInterface')}",
            data: {
                'type': type,
                'servcode': servcode,
                'url': url
            }, // 你的formid
            async: false,
            error: function(request) {
                alert("Connection error");
            },
            success: function(data) {
                var status = data['status'];
                if (!status) {
                    // window.location = "{:U('config/syncinterfaceconfig')}"

                    window.returnValue = true;
                    close();
                } else {
                    $("#tips").text(data['info']);
                }

            }
        });
        return false;


    }
    </script>
</head>

<body>
    <form action="addsyncinterface" method="post" accept-charset="utf-8" onsubmit="return validate(this)">
        <h4>第三方同步配置</h4>
        <br>
        <br> 类型:
        <select name="type" onchange="selectType(this)">
            <option value="0">包月</option>
            <option value="1">点播</option>
        </select>
        <br>
        <br> 接口地址:
        <input type="text" name="url" tips="第三方同步接口地址">
        <br>
        <br> 指令:
        <select name="servcode" id="servcode">
            <option value="WTD">WD</option>
            <option value="WTV">WV</option>
            <option value="WTS">WS</option>
        </select>
        <br>
        <br>
        <input type="submit" value="提交" class="UIbutton" onclick="return addSyncInterface()">
        <label class="tips" id="tips"></label>
    </form>
</body>

</html>
